package com.nxn.core.service.impl;

import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.nxn.core.dao.EntityDao;
import com.nxn.core.dao.RoleAuthDao;
import com.nxn.core.model.RoleAuth;
import com.nxn.core.model.User;
import com.nxn.core.service.RoleAuthService;

/**
 * Implement Services needed to edit and save
 * a role object's state.
 * @author Michael
 *
 */

@Service
public class RoleAuthServiceImpl extends EntityManagerImpl<RoleAuth, Long> implements RoleAuthService {
	
    @Autowired
	private RoleAuthDao roleAuth;
	
	@Override
	public EntityDao<RoleAuth, Long> getSearchImpl() {
		return roleAuth;
	}

	public List<RoleAuth> findMenuResourceByRoles(Collection<Long> roleIds) {
		if(roleIds != null && roleIds.size() > 0) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("roles", roleIds);
			List<RoleAuth> menuResources = roleAuth.findByNamedQueryAndNameParam("findMenuResourceByRoles", map);
			
			return menuResources;
		}
		
		return null;
	}
	
}
